<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function(){
	var myform=document.myform;
	var names=myform.names;
	var spans=document.getElementsByTagName('span')[0];
	myform.flag=false;
	//myform.onsubmit=function(){
//		if(names.value==''){
//			alert('用户名不能为空')
//			return false;	
//		};	
//	}	
	names.onblur=function(){
		var reg=/^[a-z]\w{2,10}$/;
		var val=this.value;
		if(reg.test(val)){
			spans.innerHTML='right';	
			spans.style.color='green';
			myform.flag=true;
		}else{
			spans.innerHTML='wrong';	
			spans.style.color='red';
		}	
	};
	myform.onsubmit=function(){
		if(!this.flag){
			alert('请输入完整信息');
			return false;	
		};	
	};
};
</script>
</head>

<body>
<form action="ff" method="post" name="myform">
	用户名：<input type="text" name="names" /><span></span>
    <input type="submit" value="提交" />
</form>
</body>
</html>
